package com.example.fj2889.yuedongplayer;

import android.os.Environment;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by fj2889 on 2017/6/21.
 */
public class ScanVedioList {
    public static List<String> list =new ArrayList<>();
    public ScanVedioList(){
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
            try{
                String[] ext={".mp4",".flv"};
                File file =new File(Environment.getExternalStorageDirectory()+"");
                searchVideo(file,ext);
            }catch (Exception e){}
        }
    }
    private void searchVideo(File file,String[] ext){
        if (file!=null){

            if (file.isDirectory()){
                File[] listFile=file.listFiles();
                if (listFile!=null){
                    for (int i=0;i<listFile.length;i++){

                        searchVideo(listFile[i],ext);
                    }
                }
            }
            else {
                String filename=file.getAbsolutePath();
                for (int i=0;i<ext.length;i++){
                    if (filename.endsWith(ext[i])){
                        list.add(filename);
                        break;
                    }
                }
            }
        }
    }
}
